import { SkillMainPanel } from "../SkillMainPanel";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { DataEvent } from "../../../events/DataEvent";
import { SkillInfo } from "../../../model/SkillInfo";
import { SkillConst } from "../SkillConst";
import { SkillBaseOrePanel } from "./SkillBaseOrePanel";
import { SkillBaseInfoPanel } from "./SkillBaseInfoPanel";
import { SkillItem } from "../SkillItem";
import { SkillBaseListPanel } from "./SkillBaseListPanel";
//class SkillBasePanel
    
    export  class SkillBasePanel extends SkillMainPanel
    {
        constructor()
        {
            super();
            Dispatcher.addEventListener(EventName.SkillBaseInfoShow, this.onSkillBaseInfoShowHandler);
            Dispatcher.addEventListener(EventName.SkillBaseInfoHide, this.onSkillBaseInfoHideHandler);
            return;
        }

        /* internal  */onSkillBaseInfoShowHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SkillInfo;
            if (loc1.skillId == SkillConst.Ore) 
            {
                if (!this._skillBaseOrePanel) 
                {
                    this._skillBaseOrePanel = new SkillBaseOrePanel();
                    this._skillBaseOrePanel.x = 256;
                    this._skillBaseOrePanel.y = 0;
                }
                if (!this._skillBaseOrePanel.parent) 
                {
                    this._skillBaseOrePanel.updateData(loc1);
                    this._skillBaseOrePanel.updateNewEnergy();
                    this.addChild(this._skillBaseOrePanel);
                }
                if (_skillInfo.parent) 
                {
                    _skillInfo.parent.removeChild(_skillInfo);
                }
            }
            return;
        }

        /* internal  */onSkillBaseInfoHideHandler(arg1: DataEvent): void
        {
            if (!_skillInfo.parent) 
            {
                addChild(_skillInfo);
            }
            if (this._skillBaseOrePanel && this._skillBaseOrePanel.parent) 
            {
                this._skillBaseOrePanel.parent.removeChild(this._skillBaseOrePanel);
            }
            return;
        }

        public updateNewEnergy(): void
        {
            if (this._skillBaseOrePanel && this._skillBaseOrePanel.parent) 
            {
                this._skillBaseOrePanel.updateNewEnergy();
            }
            return;
        }

        public /* override */ initSkill(arg1: Array<any>, arg2: Boolean=true): void
        {
            _skillList.initSkill(arg1);
            (_skillInfo as SkillBaseInfoPanel).initList(arg1);
            var loc1=arg1[0];
            if (loc1) 
            {
                _skillList.itemClick(loc1.position);
            }
            return;
        }

        public addSkill(arg1: SkillInfo): void
        {
            _skillList.addSkill(arg1);
            (_skillInfo as SkillBaseInfoPanel).addSkill(arg1);
            return;
        }

        protected onSkillMapClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as SkillItem;
            if (loc1 == null) 
            {
                return;
            }
            _skillList.itemClick(loc1.data.position);
            return;
        }

        protected /* override */ creatChirldren(): void
        {
            super.creatChirldren();
            _skillList = new SkillBaseListPanel();
            _skillList.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSkillMapClickHandler);
            addChild(_skillList);
            _skillInfo = new SkillBaseInfoPanel();
            addChild(_skillInfo);
            return;
        }

        protected /* override */ updateSize(): void
        {
            _skillList.x = 0;
            _skillList.y = 0;
            _skillInfo.x = 256;
            _skillInfo.y = 0;
            return;
        }

        protected /* var */_skillBaseOrePanel: SkillBaseOrePanel;
    }
